// 应用基础类型定义

// 主题类型
export type ThemeType = 'light' | 'dark' | 'auto';

// 导航项类型
export interface NavigationItem {
  id: string;
  label: string;
  icon: string;
  path: string;
  shortcut?: string;
  badge?: number;
  disabled?: boolean;
}

// 窗口状态类型
export interface WindowState {
  width: number;
  height: number;
  x?: number;
  y?: number;
  maximized: boolean;
  minimized: boolean;
}

// 应用状态类型
export interface AppState {
  theme: ThemeType;
  sidebarCollapsed: boolean;
  currentPage: string;
  windowState: WindowState;
}

// 通知类型
export interface NotificationOptions {
  title: string;
  body?: string;
  icon?: string;
  silent?: boolean;
  timeout?: number;
  actions?: Array<{
    type: string;
    text: string;
  }>;
}

// 对话框选项类型
export interface DialogOptions {
  type?: 'info' | 'warning' | 'error' | 'question';
  title?: string;
  message: string;
  detail?: string;
  buttons?: string[];
  defaultButton?: number;
  cancelButton?: number;
}

// 文件对话框选项类型
export interface OpenFileDialogOptions {
  title?: string;
  defaultPath?: string;
  filters?: Array<{
    name: string;
    extensions: string[];
  }>;
  properties?: Array<
    | 'openFile'
    | 'openDirectory'
    | 'multiSelections'
    | 'showHiddenFiles'
  >;
}

export interface SaveFileDialogOptions {
  title?: string;
  defaultPath?: string;
  filters?: Array<{
    name: string;
    extensions: string[];
  }>;
}

// 配置项类型
export interface ConfigItem {
  key: string;
  value: any;
  type: 'string' | 'number' | 'boolean' | 'object' | 'array';
  description?: string;
  defaultValue?: any;
}

// 错误类型
export interface AppError {
  code: string;
  message: string;
  details?: any;
  stack?: string;
}

// 事件类型
export interface AppEvent {
  type: string;
  payload?: any;
  timestamp: number;
}

// 连接状态类型
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error' | 'reconnecting';

// 认证方式类型
export type AuthType = 'password' | 'key' | 'keyboard-interactive';

// 端口转发类型
export type PortForwardType = 'local' | 'remote' | 'dynamic';

// 操作系统类型
export type OsType = 'linux' | 'windows' | 'macos' | 'unknown';

// 端口转发规则
export interface PortForwardRule {
  id: string;
  type: PortForwardType;
  localPort?: number;      // 本地端口（local和dynamic类型）
  remoteHost: string;      // 远程主机
  remotePort: number;      // 远程端口
  enabled: boolean;        // 是否启用
}

// 连接分组类型
export interface ConnectionGroup {
  id: string;
  name: string;
  color?: string;          // 分组颜色
  description?: string;    // 分组描述
  order: number;           // 排序顺序
  createdAt: Date;
  updatedAt: Date;
}

// 连接历史记录
export interface ConnectionHistory {
  id: string;
  connectionId: string;    // 连接ID
  connectionName: string;  // 连接名称
  connectionTime: Date;    // 连接时间
  disconnectTime?: Date;   // 断开时间
  duration?: number;       // 连接时长（秒）
  success: boolean;        // 是否成功
  errorMessage?: string;   // 错误信息
  ip?: string;             // 连接IP
}

// 连接认证信息（敏感信息）
export interface ConnectionAuth {
  id: string;
  connectionId: string;    // 连接ID
  authType: AuthType;      // 认证方式
  username: string;        // 用户名
  password?: string;       // 密码（加密存储）
  privateKey?: string;     // 私钥内容（加密存储）
  keyPassword?: string;    // 密钥密码（加密存储）
  updatedAt: Date;         // 更新时间
}

// 连接完整信息
export interface ConnectionInfo {
  id: string;
  name: string;
  host: string;
  port: number;
  username: string;
  authType: AuthType;
  status: ConnectionStatus;
  osType?: OsType;         // 操作系统类型
  lastConnected?: Date;
  groupId?: string;        // 所属分组ID
  tags?: string[];         // 标签
  description?: string;    // 描述
  timeout?: number;        // 超时时间（秒）
  keepAlive?: boolean;     // 保持连接
  keepAliveInterval?: number; // 心跳间隔（秒）
  reconnectTries?: number; // 重连次数
  portForwards?: PortForwardRule[]; // 端口转发规则
  createdAt: Date;
  updatedAt: Date;
}

// 连接配置（不包含敏感信息）
export interface ConnectionConfig {
  id: string;
  name: string;
  host: string;
  port: number;
  username: string;
  authType: AuthType;
  osType?: OsType;
  groupId?: string;
  tags?: string[];
  description?: string;
  timeout?: number;
  keepAlive?: boolean;
  keepAliveInterval?: number;
  reconnectTries?: number;
  portForwards?: PortForwardRule[];
  createdAt: Date;
  updatedAt: Date;
}

// 文件信息类型
export interface FileInfo {
  name: string;
  path: string;
  size: number;
  type: 'file' | 'directory';
  permissions: string;
  modified: Date;
  created?: Date;
}

// 传输进度类型
export interface TransferProgress {
  id: string;
  filename: string;
  bytesTransferred: number;
  totalBytes: number;
  speed: number;
  status: 'pending' | 'transferring' | 'completed' | 'error';
}

// AI消息类型
export interface AIMessage {
  id: string;
  type: 'user' | 'assistant';
  content: string;
  timestamp: Date;
  suggestions?: string[];
}

// 终端会话类型
export interface TerminalSession {
  id: string;
  connectionId: string;
  title: string;
  active: boolean;
  history: string[];
  createdAt: Date;
  lastActivity: Date;
}